package com.lzk;

import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
//开启eureka客户端功能，默认自动开启
@EnableEurekaClient
//开启hystrix熔断
@EnableCircuitBreaker
public class OrderApp {

    public static void main(String[] args) {
        SpringApplication.run(OrderApp.class,args);
    }


    /**
     * 实例化resttemplate对象在spring容器中，必须在配置类中才行(SpringBootApplication 算配置类)
     * @return
     */
    @Bean
    @LoadBalanced // 让RestTemplate拥有负载均衡能力
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    /**
     * Ribbon内置算法，使用方法
     * 随机选取
     * @return
     */
    @Bean
    RandomRule randomRule(){
        return new RandomRule();
    }
}
